home *** CD-ROM | disk | FTP | other *** search
/ Aminet 5 / Aminet 5 - March 1995.iso / Aminet / dev / misc / LEDA_gene.lha / LEDA-3.1c-generic / incl / LEDA / node_matrix.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-05  |  2.3 KB  |  90 lines

  1. /*******************************************************************************
  2. +
  3. +  LEDA  3.1c
  4. +
  5. +
  6. +  node_matrix.h
  7. +
  8. +
  9. +  Copyright (c) 1994  by  Max-Planck-Institut fuer Informatik
  10. +  Im Stadtwald, 6600 Saarbruecken, FRG     
  11. +  All rights reserved.
  12. *******************************************************************************/
  13.  
  14.  
  15. #ifndef LEDA_NODE_MATRIX_H
  16. #define LEDA_NODE_MATRIX_H
  17.  
  18. #include <LEDA/graph.h>
  19.  
  20. //------------------------------------------------------------------------------
  21. // node matrices
  22. //------------------------------------------------------------------------------
  23.  
  24.  
  25. class Node_Matrix {
  26.  
  27. graph* g;
  28. node_array<graph_array<node>*> M;
  29. virtual void init_entry(GenPtr&)  { }
  30. virtual void copy_entry(GenPtr&)  const { }
  31. virtual void clear_entry(GenPtr&) const { }
  32.  
  33. public:
  34.  
  35.  graph_array<node>& row(node v)         { return *(M[v]); }
  36.  GenPtr&      entry(node v, node w)     { return M[v]->entry(w); }
  37.  GenPtr       inf(node v, node w) const { return M[v]->inf(w); }
  38.  
  39.  void init(const graph&, int, GenPtr);
  40.  void init(const Node_Matrix&);
  41.  
  42.  void clear();
  43.  
  44.  Node_Matrix()  {}
  45. virtual ~Node_Matrix()  { clear(); }
  46. };
  47.  
  48.  
  49.  
  50.  
  51. template<class type>
  52.  
  53. class _CLASSTYPE node_matrix: public Node_Matrix {
  54.  
  55. type X;
  56.  
  57. void copy_entry(GenPtr& x) const { x=Copy(ACCESS(type,x)); }
  58. void clear_entry(GenPtr& x)const { Clear(ACCESS(type,x));  }
  59. void init_entry(GenPtr& x)       { Init(X); x = Copy(X);   }
  60.  
  61. public:
  62. node_array<type>& operator[](node v)
  63. { return *(node_array<type>*)&row(v); }
  64.  
  65. type& operator()(node v, node w)       { return ACCESS(type,entry(v,w));}
  66. type  operator()(node v, node w) const { return ACCESS(type,inf(v,w));}
  67.  
  68. void  init(const graph& G, int n, type i) { Node_Matrix::init(G,n,Convert(i)); }
  69. void  init(const graph& G, type i)        { init(G,G.max_i(node(0))+1,i); }
  70. void  init(const graph& G)                { Init(X); init(G,X); }
  71.  
  72. void  init(const node_matrix<type>& M) { Node_Matrix::init(M); }
  73.  
  74. node_matrix() {}
  75. node_matrix(const graph& G)                 { init(G);   }
  76. node_matrix(const graph& G, int n, type x)  { init(G,n,x); }
  77. node_matrix(const graph& G, type x)         { init(G,x); }
  78.  
  79. node_matrix(const node_matrix<type>& M)     { init(M); }
  80.  
  81. node_matrix<type>& operator=(const node_matrix<type>& M)
  82.                                             { init(M); return *this;}
  83.  
  84. ~node_matrix()                 { clear();   }
  85. };
  86.  
  87.  
  88. #endif
  89.